﻿Imports System.ExecutorServices
Imports System.Runtime.CompilerServices
Imports System.Aspect

Namespace Data.Objects

    Public Module SalesOrder

        <Item("SalesOrder", "sales order")> Public Interface ISalesOrder
            <Field("SalesOrderID", "sales order id")> Property SalesOrderID() As Integer
        End Interface

        <Aspect.PrimaryType(GetType(ISalesOrder))> _
        Public Interface ISalesOrderInfo
            Inherits ISalesOrder
            Inherits Customer.ICustomer
            <Field("OrderDate", "order date")> Property OrderDate() As DateTime
            <Field("CreateDate", "create date")> Property CreateDate() As DateTime
        End Interface

        'DTO-style interface
        <Aspect.PrimaryType(GetType(ISalesOrder))> _
        Public Interface ISalesOrderFullInfo
            Inherits ISalesOrderInfo
            Inherits Customer.ICustomerInfo
        End Interface

        Public Function AddLine(ByVal s As ISalesOrder, ByVal p As IProduct, ByVal qty As Decimal) As ISalesOrderLineInfo
            Return SalesOrderLine.AddSalesOrderLine(s, p, qty)
        End Function

        Public Function AddSalesOrder(ByVal c As ICustomer, ByVal OrderDate As DateTime) As ISalesOrderInfo
            Return _AddSalesOrder(c.CustomerID, OrderDate)
        End Function

        Private _AddSalesOrder As dcGetNew = Aspect(Of dcGetNew)()
        <DataCall("AddANewSalesOrder", "add a new sales order")> Private Delegate Function dcGetNew( _
        <Field("CustomerID", "customer id")> ByVal CustomerID As Integer, ByVal OrderDate As DateTime) As ISalesOrderInfo

        Public GetAll As dcGetAll = Aspect(Of dcGetAll)()
        <DataCall("GetAllSalesOrders", "get all sales orders")> Public Delegate Function dcGetAll() As ISalesOrderInfo()

        Public GetAllWithFullInfo As dcGetAllWithFullInfo = Aspect(Of dcGetAllWithFullInfo)()
        <DataCall("GetAllSalesOrderDTOs", "get all sales order DTOs")> Public Delegate Function dcGetAllWithFullInfo() As ISalesOrderFullInfo()

        <Extension()> _
        Public Sub DeleteThisSalesOrder(ByVal s As ISalesOrder)
            _Delete(s.SalesOrderID)
        End Sub

        Private _Delete As dcDelete = Aspect(Of dcDelete)()
        <DataCall("DeleteSalesOrder", "delete a sales order")> Private Delegate Sub dcDelete( _
        <Field("SalesOrderID", "sales order id")> ByVal SalesOrderID As Integer)

    End Module

End Namespace